'''
Created on 2011-9-18

@author: 123kangta
'''
import unittest

from core.container import SessionStorage, SocketTypeError
from test import generator

socket_server = generator.create_socket_server()


class SocketManagerTest(unittest.TestCase):
    def setUp(self):
        self.session = generator.create_session()

    def tearDown(self):
        self.session.close_session()

    def test_add_success(self):
        manager = SessionStorage()
        manager.add(self.session)
        self.assertEqual(1, len(manager), "应该有一条记录")

    def test_add_failure(self):
        manager = SessionStorage()
        self.assertRaises(SocketTypeError, manager.add, 123)

    def test_del_success(self):
        manager = SessionStorage()
        manager.add(self.session)
        manager.remove(self.session)
        self.assertEqual(0, len(manager), "")

    def test_del_failure(self):
        manager = SessionStorage()
        manager.add(self.session)
        self.assertRaises(SocketTypeError, manager.remove, self.session.sid)
